﻿using System;
using System.Collections;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text;


namespace integrationServer
{
    class HttpServer
    {
        // To configure the server 
        private string ipAddress;
        private int port;

        // Listens for connections from TCP network clients
        private TcpListener listener;

        public HttpServer(String ip, int port)
        {
            this.ipAddress = ip;
            this.port = port;
        }

        // The server listen
        public void listen()
        {
            IPAddress ip = IPAddress.Parse(this.ipAddress);
            
            // Launch the listener 
            listener = new TcpListener(ip, this.port);
            listener.Start();

            while (true) {  
                // Accept the connexion
                TcpClient s = listener.AcceptTcpClient();

                // Call my class in a thread to treat 
                HttpProcessor processor = new HttpProcessor(s);
                Thread thread = new Thread(new ThreadStart(processor.process));
                thread.Start();
                Thread.Sleep(1);
            }
        }
    }
}